package com.example.SocialApplication.activity.things;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;

import android.view.View;
import android.widget.Button;
import com.example.SocialApplication.R;
import com.example.SocialApplication.activity.BaseActivity;
import com.example.SocialApplication.activity.MainActivity;
import com.example.SocialApplication.activity.things.fragments.AllThingsFragment;
import com.example.SocialApplication.activity.things.fragments.MyOwnThingsFragment;

public class ThingsActivity extends BaseActivity {

    private ViewPager pager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.things_layout);

        //pager = (ViewPager) findViewById(R.id.things_pager);
        ThingsFragmentAdapter adapter = new ThingsFragmentAdapter(getSupportFragmentManager());
        pager.setAdapter(adapter);

        Button button = (Button) findViewById(R.id.add_thing);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ThingsActivity.this, AddNewThingActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Intent intent;
        switch (item.getItemId()) {
//            case R.id.CREATE_NEW:
//                intent = new Intent(this, AddNewListActivity.class);
//                startActivity(intent);
//                return true;
            case R.id.LISTS:
//                intent = new Intent(this, MainActivity.class);
//                startActivity(intent);
                return true;
            case R.id.PEOPLE:
                return true;
            case R.id.THINGS:
                intent = new Intent(this, ThingsActivity.class);
                startActivity(intent);
                return true;
        }
        return true;
    }

    private class ThingsFragmentAdapter extends FragmentStatePagerAdapter {

        public ThingsFragmentAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            Fragment fragment = null;
            switch (i) {
                case 0:
                    fragment = new MyOwnThingsFragment();
                    return fragment;
                case 1:
                    fragment = new AllThingsFragment();
            }
            return fragment;
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch(position) {
                case 0:
                    return "Мои вещи";
                case 1:
                    return "Все вещи";
                default:
                    return "tittle";
            }

        }
    }
}
